package a09_贪心算法;

/**
 * <p>
 * a13_柠檬水找零复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/24
 */
public class a13_柠檬水找零复习2 {
    public boolean lemonadeChange(int[] bills) {
        int five = 0;
        int ten = 0;
        int twenty = 0;

        for (int bill : bills) {
            if (bill == 5) {
                five++;
            }else if(bill == 10){
                if(five == 0){
                    return false;
                }else {
                    five--;
                    ten++;
                }
            }else if(bill == 20){
                if (five == 0) {
                    return false;
                }else if(ten > 0){
                    ten--;
                    five--;
                    twenty++;
                }else {
                    if(five < 3){
                        return false;
                    }else {
                        five-=3;
                    }
                }
            }
        }
        return true;
    }
}
